Bridge Crossing: Minimum distance problem

What geometrical condition gives a minimum distance between towns A and B?

w

General Solution

x

x

Min

w = 135.8 (slider from 0.1 to 500, step 0.1)
d = 1285.7 (slider from 0 to 5000, step 0.1)
b = 178.6 (slider from 0 to 500, step 0.1)
a = 278.6 (slider from 0 to 500, step 0.1)
B_W: (a * d / (a + b), a + w)
A_W: (a * d / (a + b), a)
e = Segment(A_W, B_W)
i = OrthogonalLine(A_W, e)
L = Intersect(i, yAxis)
F = Point(i)
D = Point(i)
h = OrthogonalLine(B_W, e)
E = Point(h)
C = Point(h)
poly1, d_1, f_1, e_1, c_1 = Polygon(D, F, E, C)
H = Point(d_1)
f(x) = sqrt(a^(2) + x^(2)) + w + sqrt(b^(2) + (d - x)^(2))
A = (0, 0)
B: (d, a + w + b)
c = Segment(A, A_W)
g = Segment(B_W, B)
Min_T: (a * d / (a + b), w + sqrt((a + b)^(2) + d^(2)))
yMin_T: y(Min_T)
j = OrthogonalLine(B, xAxis)
G = Intersect(j, xAxis)
k = Segment(B, G)
l = OrthogonalLine(H, d_1)
I = Intersect(h, l)
m = Segment(H, I)
n = Segment(I, B)
p = Segment(H, A)
D_1 = Distance(A, H)
D_2 = Distance(H, I)
D_3 = Distance(I, B)
dTmp: x(H)
TTmp: D_1 + D_2 + D_3
text2: "Distance A to B = " + TTmp + ""
TmpMin_T: (x(H), TTmp)
o = true
J = Point(d_1)
u = Vector(L, H)
q = Segment(J, H)
r = OrthogonalLine(TmpMin_T, yAxis)
K = Intersect(r, yAxis)
v = Vector(K, TmpMin_T)
text1: "Min distance A to B = " + yMin_T + ""
s = false